package com.webchat.client.mall.controller;


import com.webchat.client.mall.service.MallShopService;
import com.webchat.common.bean.APIResponseBean;
import com.webchat.common.bean.APIResponseBeanUtil;
import com.webchat.common.helper.SessionHelper;
import com.webchat.domain.vo.request.mall.ShopSubmitRequestVO;
import com.webchat.domain.vo.response.mall.MallShopBaseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/mall-service/shop")
public class MallShopController {

    @Autowired
    private MallShopService mallShopService;

    /**
     * 申请开店/更新店铺信息
     *
     * @param requestVO
     * @return
     */
    @PostMapping("/submit")
    public APIResponseBean<Long> submit(@RequestBody ShopSubmitRequestVO requestVO) {
        // 设置操作人信息
        String loginUserId = SessionHelper.getCurrentUserId();
        requestVO.setOperator(loginUserId);
        Long shopId = mallShopService.submit(requestVO);
        return APIResponseBeanUtil.success(shopId);
    }

    /**
     * 查询当前账号下的店铺信息
     *
     * @return
     */
    @GetMapping("/info")
    public APIResponseBean<MallShopBaseVO> shopInfo() {
        String userId = SessionHelper.getCurrentUserId();
        return APIResponseBeanUtil.success(mallShopService.shopInfo(userId));
    }
}
